package com.installtime.demo.Interceptor.validator;


import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Validator;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;

import java.io.File;

/**
 * @Classname TestUploadValidator
 * @Description TODO
 * @Date 2020/7/1 9:38
 * @Created by W.Z
 */
public class TestUploadValidator extends com.jfinal.validate.Validator {

    @Override
    protected void validate(Controller c) {

        setRet(Ret.fail());
        validateRequiredString("filePath","filePathMsg","filePath不能为空");
        String filePath = c.getPara("filePath");
        File file = new File(filePath);
        Assert.isTrue(file.exists(),"参数{}找不到{}","filePath",filePath);
    }

    @Override
    protected void handleError(Controller c) {

        c.renderJson(getRet());
    }
}
